import Vue from "vue";
import VueRouter from "vue-router";

const originalPush = VueRouter.prototype.push;
// 重写原型上的push方法，统一处理错误信息
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/layout", //路由懒加载 ,防止白屏，优化性能
  },
  {
    path: "/detail",
    component: () => import("@/views/detail"), //路由懒加载 ,防止白屏，优化性能
  },
  {
    path: "/login",
    component: () => import("@/views/login"),
  },
  {
    path: "*",
    component: () => import("@/views/notfond"),
  },
  {
    path: "/layout",
    component: () => import("@/views/layout"),
    redirect: "/layout/home",
    children: [
      {
        path: "home",
        component: () => import("@/views/home"),
      },
      {
        path: "house",
        component: () => import("@/views/house"),
      },
      {
        path: "my",
        component: () => import("@/views/my"),
      },
      {
        path: "news",
        component: () => import("@/views/news"),
      },
    ],
  },
  {
    path: "/favorate",
    component: () => import("@/views/favorate"),
  },
  {
    path: "/rent",
    component: () => import("@/views/rent"),
  },
  {
    path: "/mymap",
    component: () => import("@/views/mymap"),
  },
  {
    path: "/citylist",
    component: () => import("@/views/citylist"),
  },
];

const router = new VueRouter({
  routes,
});

export default router;
